import random
import time
from database import Mysql
import conf


def update_store(db):
    # 抽取所有变量为方法成员变量
    # 操作人信息
    operator_id = conf.storage_dept_staff["id"]
    operator_name = conf.storage_dept_staff["name"]

    # 1、更新出库单的创建人id、创建人姓名、最后更新人id、最后更新人姓名
    sql1 = """
        UPDATE wms_outbound_form 
        SET creator_id = %s, last_updater_id = %s, 
            creator_name = %s, last_updater_name = %s
    """
    count1 = db.update(
        sql1, (operator_id, operator_id, operator_name, operator_name)
    )
    print(f"sql1 更新出库单操作人: 影响 {count1} 行")

    # 2、更新出库物料单的创建人id、创建人姓名、最后更新人id、最后更新人姓名
    sql2 = """
        UPDATE wms_outbound_form_goods 
        SET creator_id = %s, last_updater_id = %s, 
            creator_name = %s, last_updater_name = %s
    """
    count2 = db.update(
        sql2, (operator_id, operator_id, operator_name, operator_name)
    )
    print(f"sql2 更新出库单物料操作人: 影响 {count2} 行")

    # 3、更新入库单的创建人id、创建人姓名、最后更新人id、最后更新人姓名
    sql3 = """
        UPDATE wms_inbound_form 
        SET creator_id = %s, last_updater_id = %s, 
            creator_name = %s, last_updater_name = %s
    """
    count3 = db.update(
        sql3, (operator_id, operator_id, operator_name, operator_name)
    )
    print(f"sql3 更新入库单操作人: 影响 {count3} 行")

    # 4、更新入库物料单的创建人id、创建人姓名、最后更新人id、最后更新人姓名
    sql4 = """
        UPDATE wms_inbound_form_goods 
        SET creator_id = %s, last_updater_id = %s, 
            creator_name = %s, last_updater_name = %s
    """
    count4 = db.update(
        sql4, (operator_id, operator_id, operator_name, operator_name)
    )
    print(f"sql4 更新入库单物料操作人: 影响 {count4} 行")

    db.commit()
